package com.server.llh.llhserverwork.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


import com.llh.llhsuppliers.R;
import com.server.llh.llhserverwork.bean.Constants;
import com.server.llh.llhserverwork.bean.ProCateService;
import com.squareup.picasso.Picasso;

import java.util.List;


public class LLHServerAdapter extends BaseAdapter{
    private ProCateService infoData;
    List<ProCateService> listData;
    public List<ProCateService> getListData() {
        return listData;
    }
    public void setListData(List<ProCateService> listData) {
        this.listData = listData;
    }

    private Context context;
    public LLHServerAdapter(Context context, List<ProCateService> listData) {
        this.context=context;
        this.listData=listData;
    }
    @Override
    public int getCount() {
        if (listData == null || listData.size() == 0) {
            return 0;
        }
        return listData.size();
    }

    @Override
    public Object getItem(int position) {
        return listData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(
                    R.layout.server_menu_item, parent, false);
            holder = new ViewHolder();
            holder.list_item_btn1 = (TextView) convertView
                    .findViewById(R.id.list_item_btn1);
            holder.imag_server = (ImageView) convertView
                    .findViewById(R.id.imag_server);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        infoData = listData.get(position);
        holder.list_item_btn1.setText(infoData.getCateName());
        if (!TextUtils.isEmpty(infoData.getPictureUrl())&&!"".equals(infoData.getPictureUrl())){
            Picasso.with(context).load(Constants.SER_IMAGE_URL+infoData.getPictureUrl()).into(holder.imag_server);
        }else{
            holder.imag_server.setBackgroundResource(R.drawable.icon_launcher);
        }
        return convertView;
    }
    class ViewHolder{
        TextView list_item_btn1;
        ImageView imag_server;
    }

}
